import java.io.IOException;
import java.util.HashMap;

public class Main{

	/**
	 * @param args
	 */
	public static HashMap<Long, Long> map = new HashMap<Long, Long>();

	public static long f(long n) {
		if (n == 0) {
			return n;
		}
		Long val = map.get(new Long(n));
		if (val == null) {
			long temp = Math.max(n, f(n / 2) + f(n / 3) + f(n / 4));
			map.put(new Long(n), new Long(temp));
			return temp;
		}
		return val.longValue();
	}

	public static void main(String[] args) throws IOException {

		java.io.BufferedReader r = new java.io.BufferedReader(
				new java.io.InputStreamReader(System.in));

		while (true) {
			if (!r.ready()) {
				break;
			}
			String s = r.readLine();
			long number = Long.parseLong(s);
			System.out.println(f(number));
		}
	}
}
